<include file="Public:head" xmlns:H="http://www.w3.org/1999/xhtml"/>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>轮播编辑</h5>
            <div class="ibox-tools" style="margin-top: -9px;">
                <a href="javascript:history.go(-1);" class="btn btn-primary"><i class="fa fa-arrow-left"></i> 返回</a>
            </div>
        </div>
        <div class="ibox-content">
            <form action="" method="post" enctype="multipart/form-data" id="brandForm" class="form-horizontal">
                <input type="hidden" name="id" value="{$da.id?$da.id:'';}">
                <div class="form-group">
                    <label class="col-sm-2 control-label">标题</label>
                    <div class="col-sm-6">
                        <input type="text" name="title" id="title" value="{$da.title?$da.title:'';}" class="form-control" placeholder="标题" >
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">状态</label>
                    <div class="col-sm-6">
                        <label class="checkbox-inline">
                            <input type="radio" name="status"  value="1"  <if condition="isset($da.status) and $da.status=='1'"> checked="checked"</if>>启用
                        </label>
                        <label class="checkbox-inline">
                            <input type="radio" name="status"  value="0"  <if condition="isset($da.status) and $da.status=='0'"> checked="checked"</if>>不启用
                        </label>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">显示位置</label>
                    <div class="col-sm-6">
                        <label class="checkbox-inline">
                            <input type="radio" name="type"  value="1"  <if condition="isset($da.type) and $da.type=='1'"> checked="checked"</if>>顶部
                        </label>
                        <label class="checkbox-inline">
                            <input type="radio" name="type"  value="2"  <if condition="isset($da.type) and $da.type=='2'"> checked="checked"</if>>中间
                        </label>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">图片</label>
                    <div class="col-sm-6">
                        <input type="file" name="img" class="form-control"><if condition="isset($da.img)">(备注: 宽度830  高度330;)<img src="__STATIC__/uploads/$da.img" alt=""></if>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">排序</label>
                    <div class="col-sm-6">
                        <input type="text" name="sort" class="form-control" value="{$da.sort?$da.sort:''}">(数字越大越排前)
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">内容介绍</label>
                    <script id="editor" name="content" type="text/plain" style="width:700px;height:300px;margin-left:290px; margin-top:-12px;">{$da.content?$da.content:''}</script>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <!--<button class="btn btn-primary" type="submit">提交</button>-->
                        <!--href="JavaScript:void(0);" onclick="roleSubmit();"-->
                        <a href="JavaScript:void(0);" onclick="Submit();" class="btn btn-primary" id="submit">提交</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- End Panel Basic -->
</div>
<script type="text/javascript" src="__STATIC__/laydate/laydate.js"></script>
<script>
    laydate.render({
        elem: '#time' //指定元素
        ,type:'datetime'
    });
    function Submit(){
        var formData = new FormData();
        var id = $('input[name="id"]').val();
        var title = $('input[name="title"]').val();
        var sort = $('input[name="sort"]').val();
        var type = $('input[name="type"]:checked').val();
        var status = $('input[name="status"]:checked').val();
        var content = ue.getContent();
        var file = $('input[name="img"]');
        var img = file.get(0).files[0];
        formData.append('id',id);
        formData.append('title',title);
        formData.append('sort',sort);
        formData.append('type',type);
        formData.append('status',status);
        formData.append('content',content);
        formData.append('img',img);

        $.ajax({
            url:"{:url('Banner/edit')}",
            type:'POST',
            data:formData,
            async:false,
            processData:false,
            contentType:false,
            success:function(result) {
                if(result.code == '0'){
                    parent.layer.alert(result.msg);
                }else{
                    parent.layer.msg(result.msg,{
                                icon:1,
                                time:1000,
                            },
                            function (index, item) {
                                location.href = result.url;
                            });
                }
            }
        });
    }
</script>
<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }


</script>
</body>

</html>